home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir43
/
qsrc_dsk.zip
/
MODEL
/
WIDGMAIN.PRG
< prev
Wrap
Text File
|
1992-01-15
|
16KB
|
473 lines
* ╓─────────────────────────────────────────────────────────╖
* ║ ║
* ║ WIDGMAIN.PRG ║
* ║ ║
* ╟─────────────────────────────────────────────────────────╢
* ║ Application Developed in _Using FoxPro 2_ ║
* ║ ║
* ║ Lisa C. Slater and Steven E. Arnott ║
* ║ ║
* ║ Copyright (c) 1991 Que Publishing ║
* ║ ║
* ╙─────────────────────────────────────────────────────────╜
* main program for second WIDGET application,
* demonstrating normal/recommended program
* "flow" and foundation READ usage.
* all additional subroutines necessary to support
* this revision of the application are included
* "bound" into this file.
DO setup
DO widglogo.spr
DO widget2.mpr
m.quit = .f.
* this KEYBOARD force "About Widget... " window
* to come up on the way
* into the foundation READ
KEYBOARD "{ALT-S}{W}"
READ VALID m.quit
DO cleanup
************************************************************************
PROC setup
ACTIVATE SCREEN
PUSH KEY CLEAR
PUSH MENU _MSYSMENU
PUBLIC m.resource, m.oldresource, m.help, m.oldhelp, m.got_cancel,;
m.olderror, m.oldtalk, m.oldvue, m.oldsafe, m.oldfull
IF SET("TALK") = "ON"
SET TALK OFF
m.oldtalk = "ON"
ENDIF
CLEAR
m.oldvue = SYS(3)+".vue"
DO WHILE FILE(m.oldvue)
m.oldvue = SYS(3)+".vue"
ENDDO
CREATE VIEW (m.oldvue)
* should also create an array to save
* record pointers here if you feel the surrounding
* environment requires that degree of protection
CLOSE DATA
m.resource = SET("RESOURCE")
m.oldresource = SET("RESOURCE",1)
m.help = SET("HELP")
m.oldhelp = SET("HELP",1)
m.olderror = IIF(EMPTY(ON("ERROR")), " ", ON("ERROR"))
m.oldsafe = SET("SAFETY")
m.oldfull = SET("FULLPATH")
SET RESOURCE ON
SET RESOURCE TO W_USER
SET FULLPATH ON
SET HELP ON
SET HELP TO Widghelp
ON ERROR DO Widgerror WITH ;
LINENO(1), PROGRAM(), ;
MESSAGE(), MESSAGE(1), ERROR(), ;
WLAST(), WREAD(), WONTOP(), RDLEVEL()
SET SYSMENU AUTOMATIC
SET SAFETY OFF
RETURN
PROC cleanup
IF "SUPPORT" $ UPPER(VERSION(1))
* DO any necessary cleanup
QUIT
ELSE
POP MENU _MSYSMENU
IF FILE(m.oldresource)
* if RESOURCE was SET OFF in CONFIG.FP,
* the file pointed to might not exist
SET RESOURCE TO (m.oldresource)
ENDIF
IF m.resource = "OFF"
SET RESOURCE OFF
ENDIF
IF FILE(m.oldhelp)
SET HELP TO (m.oldhelp)
ENDIF
IF m.help = "OFF"
SET HELP OFF
ENDIF
ON ERROR &olderror
IF ! EMPTY(m.oldtalk)
SET TALK ON
ENDIF
SET SAFETY &oldsafe
SET VIEW TO (m.oldvue)
ERASE (m.oldvue)
SET FULLPATH &oldfull
RELEASE m.resource, m.oldresource, m.help, m.oldhelp, m.got_cancel,;
m.olderror, m.oldtalk, m.oldvue, m.oldsafe, m.oldfull
* the following are PUBLIC vars setup by FoxApp that
* don't get properly released by FoxApp itself:
RELEASE bailout, dbfname, win_name, filt_expr, srchterm
* from FoxApp's generated SETUP program
RELEASE act3 && from APPCNTRL
RELEASE m.skipvar && from APPMENU
* DO other cleanup here
ACTIVATE SCREEN
FOR x = 4 TO 40 STEP .5
y = INT(x)
@ 4,y CLEAR TO 20,y
@ 4,80-y CLEAR TO 20,80-y
ENDFOR
POP KEY
ENDIF
RETURN
PROC widghelp
PARAMETERS thisvar, thisprompt, thiswind, thisfile, thistitle
PUSH KEY CLEAR
* assign help topics with your highest priority first,
* since only the first case that evaluates .T. will be
* processed -- and you can do the same thing within a
* SET TOPIC expression, as if the ORs were CASEs
* as usual the use of SET TOPIC in only one case and
* SET HELPFILTER in the others is not meant to teach you
* to use different systems all over the place;
* it's just to demonstrate different approaches and capabilities
* using this one sample system
DO CASE
CASE "Pick" $ thistitle
* in a driver Browse during data entry:
SET HELPFILTER AUTOMATIC TO ATC(thisfile,topic) > 0 OR ;
Topic = "Browse"
* Notice no quotes:
HELP Browse
CASE RDLEVEL() > 1
SET HELPFILTER AUTOMATIC TO ;
ATC(thisvar,readitem) > 0 OR ;
ATC(thistitle,topic) > 0 OR ;
ATC(ALLTRIM(windobj),thiswind) > 0 OR ;
thisfile = currfile OR ;
ATC(ALLTRIM(menuitem), thisprompt) > 0 OR ;
ATC(thisfile,topic) > 0
* is there a topic written for this GET?
* (we only did one sample, query1, in widghelp)
SET TOPIC TO ATC(thisvar, readitem) > 0
HELP
SET TOPIC TO
CASE RDLEVEL() = 1
IF ! EMPTY(thisfile)
WAIT WINDOW NOWAIT "Current table is "+PROPER(thisfile)+"... "
ENDIF
SET HELPFILTER AUTOMATIC TO ;
AT("═",topic) > 0 OR ;
ATC(thisfile,currfile) > 0 OR ;
ATC(ALLTRIM(menuitem), thisprompt) > 0
HELP
ENDCASE
POP KEY
RETURN
PROC widgerror
PARAMETERS errlineno, errprog, errmsg, errline, ;
errno, lastwind, readwind, topwind, readno
* If you are in the habit of using SET PRINT, SET CONSOLE, or
* SET DEVICE, you may have to
* SET PRINT OFF
* SET CONSOLE ON
* SET DEVICE TO SCREEN
* here and restore state later as necessary. (However, CONSOLE
* is automatically SET ON by an ON ERROR program, so there is
* no problem with the messages and WAIT WINDOWS herein being
* displayed.) The procedures here and elsewhere in the WIDGET
* rely on the ... TO <target device> clauses and NOCONSOLE keyword
* in specific commands rather than SETting PRINT or CONSOLE or
* DEVICE, which obviates this problem to a great degree.
errpdset = _PDSETUP
* The printer driver setup is removed and later
* restored in case a PostScript driver is installed,
* which would make the LISTings of MEMO and STATUS
* very difficult to read... see the PDCHECK program
* in the QDISK\MISC directory for an expanded look
* at saving printer driver-related information at
* error time, or any time. Much of that routine
* could be incorporated here.
errtalk = SET("TALK")
* one or two of the procedures may SET TALK ON temporarily
* such as PACKing...
SET TALK OFF
SET PDSETUP TO ""
* Sound a "uh-oh" sound of some sort,
* distinctive from other bells in your application
* This particular syntax is courtesy of Hallie Steiner Cooper,
* age 3 and a half <g>.
= belltone(328,3)
= belltone(261,8)
PRIVATE lowmem, errstr
PRIVATE all like ????_errs
errstr = "/" + ltrim(str(errno)) + "/"
lowmem = (val(sys(1001))-val(sys(1016)) < 10000)
* add or edit the following list as necessary
memo_errs = "/43/1012/1149/1150/1151/1600/"
indx_errs = "/5/19/20/114/1707/"
disk_errs = "/1410/"
file_errs = "/1/15/41/111/1115/1294/1643/1644/1705/"
netw_errs = "/124/1705/"
lock_errs = "/3/108/109/110/1502/1708/"
prtr_errs = "/125/"
drvr_errs = "/1910/1643/1644/1717/"
* take care of a trivial problem like this:
IF errstr $ prtr_errs
err_ask = ASK("The printer is not ready; RETRY or CANCEL?",;
"RETRY ","@M RETRY, CANCEL")
DO err_reset
IF "R" $ err_ask
RETRY
ELSE
* you may want to set a public variable in
* here that indicates that a print job was cancelled,
* as below for the record locking
RETURN
ENDIF
ENDIF
* take care of a normal situation that generates an error
* condition like this:
IF errstr $ lock_errs
err_ask = ASK("Record/file in use; RETRY or CANCEL?",;
"RETRY ","@M RETRY, CANCEL")
DO err_reset
IF "R" $ err_ask
RETRY
ELSE
got_cancel = .T.
RETURN
ENDIF
ENDIF
* take care of other classes of errors like this:
WAIT CLEAR
SET COLOR OF SCHEME 5 TO SCHEME 7
* Set WAIT WINDOW colors to alert colors, for a clear difference,
* or create a standard ALERT.SCX and use that instead --
* An ALERT.SCX will allow you to provide a fuller explanation
* of the class of error that has occurred than the one-line
* standard WAIT WINDOW, but keep in mind that an ALERT.SCX
* will require more memory than the WAIT WINDOW if you choose
* to use it.
DO CASE
* take care of an important but recoverable problem like this:
CASE UPPER(errprog) = "FILEOPEN"
* FileOpen would be a procedure that opened all
* files for your system as necessary
* Here, you'd need to take care
* of structural index not found, creating files not
* found, etc
CASE errstr $ indx_errs
WAIT WINDOW NOWAIT "Index file error detected; re-creating indexes..."
* put a re-building index program here
WAIT CLEAR
CASE errstr $ drvr_errs
* printer driver errors will be handled differently
* depending on in which way you use FP's sample printer driver
* system -- or if, instead, you have written your own _GENPD or
* _PDRIVER. See Chapter 15, and PDCHECK.PRG in the
* \MISC directory of the source disk, for appropriate
* items to check when printer driver problems are suspected.
* take care of unrecoverable errors such as out of
* memory, disk, corrupted problem files, like this:
CASE errno = 1309
WAIT WINDOW ;
"There is a problem with your program files. Please re-install."
ENDCASE
* check for unrecoverable errors that cannot be logged:
IF lowmem OR INLIST(errno, 1309, 56) && make your own list!
* write a limited log, as per instructions below,
* to the printer if possible first
WAIT WINDOW UPPER(PROGRAM(0))+;
" cannot recover from this error; "+;
"press a key to clean up & exit."
CLOSE ALL
ERASE (m.oldvue)
QUIT
ENDIF
* otherwise write a log for future use:
WAIT WINDOW NOWAIT ;
"A program exception has occurred; writing error log... "
xselect = SELECT()
IF USED("errlog")
SELECT errlog
ELSE
IF FILE("errlog.dbf") AND FILE("errlog.fpt")
SELECT 0
USE errlog
ELSE
CREATE TABLE errlog ;
(errdate d(8), ;
errtime c(8), ;
snapshot m(10), ;
listing m(10), ;
usernotes m(10))
ENDIF
ENDIF
APPEND BLANK
IF RLOCK()
* You don't need this RLOCK() and UNLOCK
* if your version of FoxPro 2 is later than October 1991,
* so get rid of them if possible!
* SAVE WINDOWS or MACROS TO MEMO... now does an automatic
* record lock in the same way as a normal REPLACE or
* APPEND MEMO... FROM does
* This RLOCK() is only included in case you have not
* updated your copy of FoxPro because errors within
* an error program are so annoying and difficult to
* recover from cleanly. In most other parts of the
* source code, we have not attempted to compensate for
* version differences. Caveat emptor!
SAVE WINDOWS ALL TO MEMO snapshot
UNLOCK
ENDIF
REPLACE errdate WITH DATE(), errtime WITH TIME()
* create listing memo field from chunks of data --
* do a couple of REPLACEs so that less memory is
* used for each step of this process
errdata = 'error number='+ALLTRIM(STR(errno))
errdata = errdata+CHR(13)+'error message='+errmsg
errdata = errdata+CHR(13)+'last error parameter='+SYS(2018)
errdata = errdata+CHR(13)+'program= '+ errprog
errdata = errdata+CHR(13)+'lineno= '+;
ALLTRIM(STR(errlineno))+": "+errline
REPLACE listing WITH errdata
errdata = CHR(13)+'bof='+IIF(BOF(),"YES","NO")
errdata = errdata+CHR(13)+ 'eof='+IIF(EOF(),"YES","NO")
errdata = errdata+CHR(13)+'last window='+lastwind
errdata = errdata+CHR(13)+'top window '+IIF(EMPTY(topwind),;
'SCREEN ',UPPER(topwind))+;
IIF(readwind, '*is*','*is NOT*')+;
' involved in current READ'
REPLACE listing WITH errdata ADDITIVE
errdata = CHR(13)+'read level='+ALLTRIM(STR(readno))
errdata = errdata+CHR(13)+ 'rec. no.='+ALLTRIM(STR(RECNO()))
errdata = errdata+CHR(13)+ 'diskspace='+ALLTRIM(STR(DISKSPACE(),25))
errdata = errdata+CHR(13)+ 'os='+OS()
errdata = errdata+CHR(13)+ 'ver='+VERSION(1)
REPLACE listing WITH errdata ADDITIVE
errdata = CHR(13)+ ALLTRIM(STR(VAL(SYS(1016))/1024))+;
"K memory in use by user objects"
errdata = errdata+CHR(13)+ ALLTRIM(STR(VAL(SYS(12))/1024))+;
"K memory remaining"
errdata = errdata+CHR(13)+ ALLTRIM(STR(VAL(SYS(1001))/1024))+;
"K total memory available to Fox"
errdata = errdata+CHR(13)+ IIF(EMPTY(errpdset),"NO",errpdset)+;
" Printer Driver Installed"
REPLACE listing WITH errdata ADDITIVE
errdata = CHR(13)+ 'processor='+ SYS(17)
errdata = errdata+CHR(13)+ 'video card/monitor='+SYS(2006)
errdata = errdata+CHR(13)+ 'FILES='+SYS(2010)
errdata = errdata+CHR(13)+CHR(13)+REPLICATE('=',50)
errdata = errdata+CHR(13)+' Status listing'
errdata = errdata+CHR(13)+REPLICATE('=',50)+CHR(13)
REPLACE listing WITH errdata ADDITIVE
RELEASE errdata
IF TYPE("gramdisk") # "C"
* gramdisk would be a variable you'd let
* them specify a workdisk with during setup;
* would have complete pathspec in it
gramdisk = ""
ENDIF
tempfile = gramdisk+SYS(3)+".tmp"
DO WHILE FILE(tempfile)
tempfile = gramdisk+SYS(3)+".tmp"
ENDDO
LIST STATUS TO (tempfile) NOCONSOLE
APPEND MEMO listing FROM (tempfile)
* APPEND MEMO is ADDITIVE by default
ERASE (tempfile)
* just in case SAFETY is still ON
* if an error occurs at the very beginning of the program!
REPLACE listing WITH CHR(13)+REPLICATE('=',50)+CHR(13)+;
' Memory listing'+CHR(13)+;
REPLICATE('=',50)+CHR(13) ;
ADDITIVE
LIST MEMORY TO (tempfile) NOCONSOLE
APPEND MEMO listing FROM (tempfile)
* add blank user questionnaire of some type
* to the user-editable memo field
APPEND MEMO usernotes FROM survey.txt
SELECT (xselect)
ERASE (tempfile)
WAIT CLEAR
SET COLOR OF SCHEME 5 TO
* re-set system parameters here as necessary
* and, if you have been event-handling in several
* apparent READs saving state in all of them, cancel
* all changes and CLEAR READ ALL
* if your foundation READ is inside a Fndation.SPR called by
* your main program, which paints a logo before
* issuing the main READ, you would change the following to
* RETURN TO Fndation.SPR
DO err_reset
RETURN TO MASTER
FUNCTION belltone
PARAMETERS f,d
* from Tom Rettig's FoxPro Handbook, with an additional check
* to save & restore bell setting
STORE SET("BELL") TO oldbell
SET BELL ON
SET BELL TO f,d
?? CHR(7)
SET BELL &oldbell
SET BELL TO
* if you routinely leave BELL ON for other activities,
* you need to set the tones back to default or to whatever
* you *use* for a default. SET("BELL",1) will not give you
* this information, unfortunately!
RETURN ""
PROC err_reset
SET TALK &errtalk
SET PDSETUP TO errpdset
RETURN